let App = getApp();
// pages/live/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    accesstoken:'',
    room_list:'',
    page:1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this;
    App._post('Getaccesstoken/getToken',{},function(res){
        console.log('zhibo',res.data)
        that.setData({
          accesstoken:res.data
        });
        App._post('Getaccesstoken/getRoomlist',{AccessToken:res.data,page:1},function(res){
          console.log('roomlist',res.data.room_info)
          that.setData({
            room_list:res.data.room_info
          });
      })
    })
 
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let that = this;
    var page = Number(that.data.page) + 1; 
    App._post('Getaccesstoken/getRoomlist',{AccessToken:that.data.accesstoken,page:page},function(res){
      console.log('roomlist',res.data.room_info)
      that.setData({
        room_list:that.data.room_list.concat(res.data.room_info),
      });
      if(res.data.errcode  == 0){
        that.setData({
          page:page
        });
      }
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  // 跳转直播间
  clickItem:function(e){
    let roomId = [e.target.dataset.id] 
    console.log('sdfsdfsf',e);
    let customParams = encodeURIComponent(JSON.stringify({ path: 'pages/live/show', pid: 1 }))
    wx.navigateTo({
        url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${roomId}&custom_params=${customParams}`
    })
  }
})